define(function(require, exports) {
	var util = require('util');
	var pubjs = require('pubjs');
	var view  = require('@base/view');

	// 编辑活动温差组件
	var Base = view.container.extend({
		init: function(config) {
			var self = this;
			config = pubjs.conf(config, {
				 'class': 'M-PageTemperatureDiff'
				,'tplFile': '/tpl/campaign/modules/temperatureDiff.tpl'
				,'view_model': {
					// 持续x天持续投放
					 'openDays': '0'
					// 最近x天的温度
					,'recentCount': '7'
					// 上升下降幅度
					,'changeCount': '0'
				}
			});

			self.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var c = self.getConfig();

			var opts = {
				tips: {
					width: 60
					,data: LANG("")
				}
				// 最低温度比较操作符
				 ,recentCountType: {
					'width': 100,
					'options': [
						{name: LANG('天'), id: 1}
						,{name: LANG('小时'), id: 2}
					],
					'value': 1,
					'panel_config': {
						'hasSearch': false
					}
				}
			}
			self.buildFromTemplate(util.extend(opts, c.tipOpts));
		}
		,reset: function() {
			this.vm.reset();
			return this;
		}
		,setData: function(data) {
			var self = this;
			var vm = self.vm.$;

			if (util.isArray(data)) {
				data = data.shift();
			}

			if (data) {
				var changes = data["Change"];
				vm.openDays = data["OpenDays"] || '';
				if (changes) {
					vm.recentCount = changes["RecentCount"] || '';
					vm.changeCount = changes["ChangeCount"] || '';
					self.$.recentCountType.setValue(changes["RecentCountType"]);
				}
			}
			return self;
		}
		,getData: function() {
			var data = {};
			var vm = this.vm.$;

			data["OpenDays"] = vm.openDays;
			data["Target"] = 3;       // 暂时固定，(1: 国家，2: 省，3: 城市)
			data["Change"] = {
				"RecentCount": vm.recentCount,
				"RecentCountType": this.$.recentCountType.getValue(true).id,
				"ChangeType": 3,      // 暂时固定（0： 不限制 1: >=，2: <=）
				"ChangeCount": vm.changeCount,
				"ChangeCountType": 2  // 暂时固定 (1: %, 2: ℃)
			}
			return [data];
		}
	});

	exports.base = Base;
});